package com.amit;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.Locale;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DemoServlet  extends HttpServlet{
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		
		//1.request parameters
		
		String un=request.getParameter("uname");
		
		//2.display request parameters
		PrintWriter out=response.getWriter();
		out.println("<h1>Username:</h1>"+un);
		
		
		System.out.println("request headers");
		//3.request Headers
		Enumeration e=request.getHeaderNames();
		
		while(e.hasMoreElements())
		{
			String hn=e.nextElement().toString();
			String hv=request.getHeader(hn);
			
			out.println("<h1>"+hn+":"+hv+"</h1>");		
		}
		//4.locales supported by browser
		System.out.println("Locale supported by browser");
		out.println("<h1>request.getLocale():"+request.getLocale()+"</h1>");
		
		out.println("<h1>All the locales supported</h1>");
		Enumeration locs=request.getLocales();
		while(locs.hasMoreElements())
		{
			Locale l=(Locale)locs.nextElement();
			out.println("<h1>"+l+"</h1>");
		}
	
		//5.other infomation From Request
		
		out.println("<h1>request.getMethod():"+request.getMethod()+"</h1>");
		out.println("<h1>request.getReuestURI():"+request.getRequestURI()+"</h1>");
		out.println("<h1>request.getReuestURL:"+request.getRequestURL()+"</h1>");
		out.println("<h1>request.getProtocol:"+request.getProtocol()+"</h1>");
		out.println("<h1>request.getScheme:"+request.getScheme()+"</h1>");
		out.println("<h1>request.getcharacterEncoding:"+request.getCharacterEncoding()+"</h1>");
		out.println("<h1>request.getcontentLength():"+request.getContentLength()+"</h1>");
		out.println("<h1>request.getcontenttype:"+request.getContentType()+"</h1>");
		out.println("<h1>request.getpathinfo():"+request.getPathInfo()+"</h1>");
		out.println("<h1>request.getReuestURI:"+request.getRequestURI()+"</h1>");
		out.println("<h1>request.getpathTranslate:"+request.getPathTranslated()+"</h1>");
		out.println("<h1>request.getRemoteAddr:"+request.getRemoteAddr()+"</h1>");
		out.println("<h1>request.getRemoteport():"+request.getRemotePort()+"</h1>");
		out.println("<h1>request.getRemotehost:"+request.getRemoteHost()+"</h1>");
		out.println("<h1>request.getlocaleaddr():"+request.getLocalAddr()+"</h1>");
		out.println("<h1>request.getlocaleport():"+request.getLocalPort()+"</h1>");
		out.println("<h1>request.getlocalename():"+request.getLocalName()+"</h1>");
		out.println("<h1>request.getserverport:"+request.getServerPort()+"</h1>");
		out.println("<h1>request.getservername:"+request.getServerName()+"</h1>");
		out.println("<h1>request.getquerystring:"+request.getQueryString()+"</h1>");
		out.println("<h1>request.getservletpath():"+request.getServletPath()+"</h1>");
		out.println("<h1>request.getcontextpath():"+request.getContextPath()+"</h1>");
		out.println("<h1>request.getremoteuser():"+request.getRemoteUser()+"</h1>");
		out.println("<h1>request.getuserprincipal():"+request.getUserPrincipal()+"</h1>");
		out.println("<h1>request.getauthtype():"+request.getAuthType()+"</h1>");
		
	
	}

}
